package com.hsq.upload;

import java.io.*;
import java.net.InetAddress;
import java.net.Socket;

public class TCPFileUploadClient {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket(InetAddress.getLocalHost(), 8888);
        //创建读取磁盘文件的输入流
        String filePath = "D:\\git_turtle\\J.jpg";
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(filePath));
        //bytes就是filepath对应的字节数组
        byte[] bytes = StreamUtils.streamToByteArray(bis);
        BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());
        bos.write(bytes);
        bis.close();
        socket.shutdownOutput();

        InputStream inputStream = socket.getInputStream();
        String s = StreamUtils.StreamToString(inputStream);
        System.out.println(s);
//        BufferedReader bufferedInputStream = new BufferedReader(
//                new InputStreamReader(inputStream)
//        );
//        String s = bufferedInputStream.readLine();
        //关闭操作
        inputStream.close();
        bos.close();
        socket.close();
    }
}
